package com.dubbo.service.impl;

import com.dubbo.common.MathUtils;
import com.dubbo.common.ResponseUtil;
import com.dubbo.common.check.CheckUtil;
import com.dubbo.common.kuaidinao.LogisticsUtil;
import com.dubbo.common.page.PageResponse;
import com.dubbo.common.page.PageUtils;
import com.dubbo.common.push.JpushClientUtil;
import com.dubbo.domain.*;
import com.dubbo.domain.Process;
import com.dubbo.domain.info.ResultMessage;
import com.dubbo.mapper.*;
import com.dubbo.mapper.other.DictMapper;
import com.dubbo.service.business.order.OrderService;
import com.dubbo.service.impl.base.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 订单serviceimpl
 * @author chenluqiang
 * @date 2018年12月18日 下午4:26:56 
 *
 */
@Service
@Transactional(readOnly=false,rollbackFor=Exception.class)
public class OrderServiceImpl extends BaseServiceImpl<Order> implements OrderService {
	
	@Autowired
	private OrderMapper orderMapper;
	@Value("${fastdfsUrl}")
	private String fastdfsUrl;
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private ORoleLevelMapper orderRoleLevelMapper;
	@Autowired
	private ProcessMapper processMapper;
	@Autowired
	private ShippingMapper shippingMapper;
	@Autowired
	private DictMapper dictMapper;
	//APP_ID
	@Value("${alipay.appid}")
	private String APP_ID;
	//日志
	private Logger logger = Logger.getLogger(this.getClass());
	@Autowired
	private MessageMapper messageMapper;
	@Value("${eBusinessID}")
	private String eBusinessID;
	@Value("${kuaidiniao_appKey}")
	private String kuaidiniaoAppKey;
	@Autowired
	private  WalletMapper walletMapper;
	@Autowired
	private AddressMapper addressMapper;
	@Autowired
	private CategoryMapper categoryMapper;
	
	/**
	 * 订单列表
	 * @author chenluqiang
	 * @date 2018年12月17日 下午2:42:37 
	 * @param type 类型 0=新订单 1=未接单 2=审核中 3=待发货 4=待收货 5=已完成
	 * @return
	 */
	@Override
	public Map<String, Object> orderList(User user, Long pageStart, Long pageTotal, Integer type) {
		//校验
		if(type==null||type<0||type>5) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_ERROR,"type is error~");
		}
		
		//初始化分页参数
		pageStart = PageUtils.initialPageStart(pageStart);
		pageTotal = PageUtils.packagePageTotal(pageTotal, 5, 10);
		//sql分页中的起始值
		Long countPageStart = PageUtils.countPageStart(pageStart, pageTotal);
		
		//获取数据列表
		List<Map<String,Object>> data = orderMapper.getOrderListByStatus(user.getId(),type,countPageStart,pageTotal,user.getType());
		Long count = orderMapper.getOrderListCountByStatus(user.getId(), type,user.getType());
		
		for(Map<String,Object> map:data) {
			//订单id
			String orderId = (String) map.get("orderId");
			int status = (int) map.get("status");   //订单状态
			int isCancel = (int) map.get("isCancel");  //是否取消订单    0=否 1=是
			int payStatus = (int)map.get("payStatus");  //订单支付状态    (0=未支付,1=已支付,2=支付失败)
			String orderUserId = (String) map.get("userId");  //下单用户id
			String cancelUserId = (String) map.get("cancelUserId");  //取消订单的用户ID
			int isTrader = (int) map.get("isTrader");  //分销商是否点击确认取消   0=否 1=是
			int isAgent = (int) map.get("isAgent");  //代理商是否点击确认取消   0=否 1=是
			int isVender = (int) map.get("isVender");  //厂家是否点击确认取消   0=否 1=是
			int showTraderPrice = 0;   //是否显示应收总价   0=否  1=是
			//取消订单的用户
			User cancelUser = null; 
			if(StringUtils.isNoneBlank(cancelUserId)) {
				cancelUser = userMapper.selectByPrimaryKey(cancelUserId);
			}
			String electId = (String) map.get("electId");  //订单用户层级关系中的电工
			String agentId = (String) map.get("agentId");  //订单用户层级关系中的代理商
			String traderId = (String) map.get("traderId");  //订单用户层级关系中的分销商
			int isReciver = 0;   //是否需要点击收货   0=否  1=是
			
			if(user.getType()==3 && (status==3 || status==5 ||status==7)) { //3=电工
				map.put("code", "2"); //审核中
				map.put("status", "审核中"); 
			}
			// 2=分销商(商家) 
			if(user.getType()==2 && status==3){
				map.put("code", "0"); //新订单
				map.put("status", "新订单"); 
			}else if(user.getType()==2 && (status==5||status==7)){
				map.put("code", "2"); //审核中
				map.put("status", "审核中"); 
			}
			// 1=代理商
			if(user.getType()==1 && status==5){
				map.put("code", "0"); //新订单
				map.put("status", "新订单"); 
			}
			else if(user.getType()==1 && status==7){
				map.put("code", "2"); //审核中
				map.put("status", "待发货"); 
			}
			if(status==8){
				map.put("code", "1"); //未接单
				map.put("status", "未接单"); 
				map.put("msg", "厂家未接单");
			}
			if(status==4 || status==6) {
				map.put("code", "1"); //未接单
				map.put("status", "未接单"); 
			}
			if(user.getType()==1 && payStatus==2) {
				map.put("code", "8"); //待付款
				map.put("status", "待付款"); 
			}
			if(status==7 || status==9) {
				map.put("code", "3"); //待发货
				map.put("status", "待发货"); 
			}
			if(status==10) {
				map.put("code", "4"); //待收货
				map.put("status", "待收货");
				//访问接口的用户是代理商
				if(user.getType()==1) {
					//下订单的用户和访问接口的用户id相同，说明是代理商下单
					if(orderUserId.equals(user.getId())) {
						isReciver=1; //需要点击收货
					}
					//电工id和代理商id不为空，分销商id为空，说明下单的用户是电工，直接上级是代理商
					if(StringUtils.isNoneBlank(electId) && StringUtils.isBlank(traderId) && StringUtils.isNoneBlank(agentId)) {
						isReciver=1; //需要点击收货
					}
				}
				//访问接口的用户是分销商
				if(user.getType()==2) {
					//下订单的用户和访问接口的用户id相同，说明是分销商下单
					if(orderUserId.equals(user.getId())) {
						isReciver=1; //需要点击收货
					}
					//电工id和分销商id不为空，说明是电工下单，分销商是电工直接上级
					if(StringUtils.isNoneBlank(electId) && StringUtils.isNoneBlank(traderId)) {
						isReciver=1; //需要点击收货
					}
				}
			}
			if (status == 11) {
				map.put("code", "5"); // 已完成
				map.put("status", "已完成");
				

				// 0=订单已申请售后,不能多次申请售后,1=厂家发货15天后仅允许换货,2=厂家发货起15天内可以选择退换货
//				String isRefund = processMapper.findIsRefundByOrderId(orderId);
				// 判断能不能申请售后
				//校验订单是否交易完成
				Map<String, Object> processMap = processMapper.findProcessByOrderId(orderId);
				if(processMap==null||processMap.isEmpty()
							||processMap.get("status")==null
							||StringUtils.isBlank(processMap.get("status").toString())
							||!processMap.get("status").toString().equals("11") //订单状态是否是已完成状态
							||!processMap.get("isRefund").toString().equals("1")) {  //是否能申请售后 0=否 1=是
//					return ResponseUtil.ajaxCheckError(ResultMessage.ORDER_APPLY_ERROR);
//				}
//				if (StringUtils.isNotBlank(isRefund) || isRefund.equals("0")) {// 是否能申请售后 0=否 1=是
					map.put("refundType", "0");// 订单已申请售后,不能多次申请售后
				} else {
					// 根据orderId获取订单发货时间到现在的天数
					String day = processMapper.findSendTimeByOrderId(orderId);
					if (StringUtils.isNotBlank(day)
							&& Integer.parseInt(MathUtils.sub(dictMapper.getVal("afterSaleTime"), day)) >= 0) {
						map.put("refundType", "2");// 厂家发货起15天内可以选择退换货
					} else {
						map.put("refundType", "1");// 厂家发货15天后仅允许换货
					}
				}
			}
			if(isCancel==1 && status!=11) {
				map.put("code", "6"); //订单取消中
				map.put("status", "订单取消中");
				if(cancelUser==null) {
					return ResponseUtil.ajaxCheckError(ResultMessage.SYSTEM_ERROR, "cancelUser is null");
				}
				//类型
				String userType = null;
				if(cancelUser.getType()==1) {
					userType="代理商";
				}else if(cancelUser.getType()==2) {
					userType="分销商";
				}else {
					userType="电工";
				}
				map.put("msg",cancelUser.getNickName()+userType+"发起订单取消");
			}
			/*if(isCancel==1 && status==11) {
				map.put("code", "7"); //已取消
				map.put("status", "已取消"); 
				if(cancelUser==null) {
					return ResponseUtil.ajaxCheckError(ResultMessage.SYSTEM_ERROR, "cancelUser is null");
				}
				//类型
				String userType = null;
				if(cancelUser.getType()==1) {
					userType="代理商";
				}else if(cancelUser.getType()==2) {
					userType="分销商";
				}else {
					userType="电工";
				}
				map.put("msg",cancelUser.getNickName()+userType+"发起订单取消");
			}*/
			if(cancelUser!=null&&isCancel==1) { 
				//分销商待审核
				if(status==3) {
					if(isTrader==1) {
						//设置订单已取消状态
						this.setOrderCancelStatus(map,cancelUser);
					}
				}
				//代理商待审核
				if(status==5) {
					//若访问接口的用户是分销商
					if(user.getType()==2) {
						if(!cancelUser.getId().equals(user.getId())) {//取消订单不是此人
							if(isTrader==1) {
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}else {
							if(isAgent==1) { //分销商取消订单，代理商审核通过
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}
					}
					//若访问接口的用户是代理商
					if(user.getType()==1) {
						//分销商取消订单，代理商审核通过
						if(isAgent==1) {
							//设置订单已取消状态
							this.setOrderCancelStatus(map,cancelUser);
						}
					}
					//若访问接口的用户是电工
					if(user.getType()==3) {
						//电工取消订单 分销商，代理商审核通过
						if(isTrader==1 && isAgent==1) {
							//设置订单已取消状态
							this.setOrderCancelStatus(map,cancelUser);
						}
					}
				}
			
				//厂家流程
				if(status>6) {
					//若访问接口的用户是分销商
					if(user.getType()==2) {
						if(!cancelUser.getId().equals(user.getId())) {//取消订单不是此人
							if(isTrader==1) {
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}else {
							if(isAgent==1 && isVender==1) {
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}
					}
					//若访问接口的用户是代理商
					if(user.getType()==1) {
						if(!cancelUser.getId().equals(user.getId())) {//取消订单不是此人
							if(isAgent==1) {
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}else {
							if(isVender==1) {
								//设置订单已取消状态
								this.setOrderCancelStatus(map,cancelUser);
							}
						}
					}
					//若访问接口的用户是电工
					if(user.getType()==3) {
						if(isTrader==1 && isAgent==1 && isVender==1) {
							//设置订单已取消状态
							this.setOrderCancelStatus(map,cancelUser);
						}
					}
				}
				
				map.remove("isCancel");
				
			}
			//访问接口的用户是代理商
			if(user.getType()==1) {
				ORoleLevel oRoleLevel = orderRoleLevelMapper.selectByPrimaryKey(orderId);
				if(StringUtils.isNotBlank(oRoleLevel.getTraderid())) {
					showTraderPrice = 1;
				}
			}
			map.put("isReciver", isReciver);  //是否需要点击确认收货  0=否，1=是
			map.put("showTraderPrice", showTraderPrice);
		}
		
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK,new PageResponse(pageStart, pageTotal,count, data));
	}
	
	/**
	 * /设置订单已取消状态
	 * @author chenluqiang
	 * @date 2019年1月22日 下午3:51:21 
	 * @param map
	 * @param cancelUser
	 */
	private void setOrderCancelStatus(Map<String, Object> map, User cancelUser) {
		map.put("code", "7"); //已取消
		map.put("status", "已取消"); 
		
		//类型
		String userType = null;
		if(cancelUser.getType()==1) {
			userType="代理商";
		}else if(cancelUser.getType()==2) {
			userType="分销商";
		}else {
			userType="电工";
		}
		map.put("msg",cancelUser.getNickName()+userType+"发起订单取消");
	}

	/**
	 * 订单详情
	 * @author lihongwu
	 * @date 2018年12月18日 下午4:16:15 
	 * @param request
	 * @param orderId 订单id
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> orderDetail(User user, String orderId) throws Exception {
		//校验orderId
		if(StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL,"orderId isnull~");
		}
		
		Map<String,Object> result = new HashMap<String,Object>();
	
		//是否有修改地址按钮 0=否 1=是
		int isEdit = 0; 
		//订单是否完成  0=否  1=是
		int isFinish = 0;
		int showTraderPrice = 0;   //是否显示应收总价   0=否  1=是
		//查询数据
		Map<String,Object> orderDetailMap =  orderMapper.getOrderDetail(orderId);
		List<Map<String,Object>> orderItemList = orderMapper.getOrderItemByOrderId(orderId);
		this.handleListPics(orderItemList, "goodsPic");
		
		//流程
		List<Map<String,Object>> processList = new ArrayList<>();
		
		Map<String,Object> map1 = new HashMap<>();
		map1.put("name", "提交");
		map1.put("title", "电工");
		map1.put("status", "2");  //status   0=白色   1=绿色  2=灰色  3=红色(未接单) 4=红色(完成) 5=红色(取消订单)
		
		Map<String,Object> map2 = new HashMap<>();
		map2.put("name", "审核");
		map2.put("title", "分销");
		map2.put("status", "0");
		
		Map<String,Object> map3 = new HashMap<>();
		map3.put("name", "审核");
		map3.put("title", "代理");
		map3.put("status", "0");
		
		Map<String,Object> map4 = new HashMap<>();
		map4.put("name", "接单");
		map4.put("title", "厂家");
		map4.put("status", "0");
		
		Map<String,Object> map5 = new HashMap<>();
		map5.put("name", "发货");
		map5.put("title", "厂家");
		map5.put("status", "0");
		
		Map<String,Object> map6 = new HashMap<>();
		map6.put("name", "收货");
		map6.put("title", "分销");
		map6.put("status", "0");
		
		Map<String,Object> map7 = new HashMap<>();
		map7.put("name", "完成");
		map7.put("title", "");
		map7.put("status", "0");
		
		processList.add(map1);
		processList.add(map2);
		processList.add(map3);
		processList.add(map4);
		processList.add(map5);
		processList.add(map6);
		processList.add(map7);
		
		//获取订单流程数据
		Map<String,Object> processDetail = processMapper.getProcessByOrderId(orderId);
		
		if(processDetail==null||processDetail.isEmpty()) {
			return ResponseUtil.ajaxCheckError(ResultMessage.ORDERID_ISERROR);
		}
		
		//获取订单流程状态
		int status = (int) processDetail.get("status");
		//获取下订单的用户
		String userId = (String) orderDetailMap.get("userId");
		User orderUser = userMapper.selectByPrimaryKey(userId);
		
		int type = 0;
		ORoleLevel oRoleLevel = orderRoleLevelMapper.selectByPrimaryKey(orderId);
		if(StringUtils.isNoneBlank(oRoleLevel.getElectid()) && StringUtils.isBlank(oRoleLevel.getTraderid()) 
				&& StringUtils.isNoneBlank(oRoleLevel.getAgentid())) { 
			type = 1;  //若分销商为空,电工和代理商id不为空,说明电工的直接上级是代理商
		}
		
		//正常流程
		if(status==3) {  //分销商待审核状态
			map2.put("status", "1");  //绿色
		}else if(status==4) {  //分销商不接单
			map2.put("name", "未接单");
			map2.put("status", "3");  // 红色(未接单)
			map7.put("status", "4");  // 红色(完成)
			isFinish = 1;
		}else if(status==5) { //代理商待审核
			map2.put("status", "2");  //灰色
			map3.put("status", "1");  //绿色
		}else if(status==6) { //代理商不接单
			map2.put("status", "2");  //灰色
			map3.put("name", "未接单");
			map3.put("status", "3");  // 红色(未接单)
			map7.put("status", "4");  // 红色(完成)
			isFinish = 1;
		}else if(status==7) { //厂家待批准
			map2.put("status", "2");  //灰色
			map3.put("status", "2");  //灰色
			map4.put("status", "1");  //绿色
		}else if(status==8) { //厂家不接单
			map2.put("status", "2");  //灰色
			map3.put("status", "2");  //灰色
			map4.put("name", "未接单");
			map4.put("status", "3");  // 红色(未接单)
			map7.put("status", "4");  // 红色(完成)
			isFinish = 1;
		}else if(status==9) {  //厂家待发货
			map2.put("status", "2");  //灰色
			map3.put("status", "2");  //灰色
			map4.put("status", "2");  //灰色
			map5.put("status", "1");  //绿色
		}else if(status==10) {  //分销商或代理商待收货
			map2.put("status", "2");  //灰色
			map3.put("status", "2");  //灰色
			map4.put("status", "2");  //灰色
			map5.put("status", "2");  //灰色
			map6.put("status", "1");  //绿色
		}else if(status==11) {
			map2.put("status", "2");  //灰色
			map3.put("status", "2");  //灰色
			map4.put("status", "2");  //灰色
			map5.put("status", "2");  //灰色
			map6.put("status", "2");  //灰色
			map7.put("status", "4");  // 红色(完成)
			isFinish = 1;  //订单已完成
		}
		
		//若订单是取消状态
		if((int)processDetail.get("isCancel")==1) {
			
			//获取取消订单的user
			User cancelUser = userMapper.selectByPrimaryKey(processDetail.get("cancelUserId"));
			/*int isTrader = (int) processDetail.get("isTrader");  //分销商是否点击确认取消按钮
			int isAgent = (int) processDetail.get("isAgent");	//代理商是否点击确认取消按钮
			int isVender = (int) processDetail.get("isVender");//厂家是否点击确认取消按钮
*/			
			Integer isTrader = (Integer) processDetail.get("isTrader");  //分销商是否点击确认取消按钮
			Integer isAgent = (Integer) processDetail.get("isAgent");	//代理商是否点击确认取消按钮
			Integer isVender = (Integer) processDetail.get("isVender");//厂家是否点击确认取消按钮
			
			if(isTrader==null||isAgent==null||isVender==null||StringUtils.isBlank(isTrader.toString())
					||StringUtils.isBlank(isAgent.toString())
					||StringUtils.isBlank(isVender.toString())) {
				return ResponseUtil.ajaxCheckError(ResultMessage.SYSTEM_ERROR, "isTrader is null");
			}
			
			//判断取消订单的用户类型
			if(cancelUser.getType()==3) {  //取消订单的用户是电工
				map1.put("name", "取消");
				map1.put("status", "5"); //红色(取消订单)
			}else if(cancelUser.getType()==2) { //取消订单的用户是分销商
				map2.put("name", "取消");
				map2.put("status", "5"); //红色(取消订单)
			}else if(cancelUser.getType()==1) { //取消订单的用户是代理商
				map3.put("name", "取消");
				map3.put("status", "5"); //红色(取消订单)
			}
			
			//判断订单状态
			if(status==3 && isTrader==1) {  //分销商审核阶段取消订单且分销商点击确认取消按钮
				map7.put("status", "4");  // 红色(完成)
			}else if(status==5) { //代理商审核阶段取消订单
				if(orderUser.getType()==3 && isTrader==1 && isAgent==1) { //下单用户为电工,且分销商,代理商点击确认取消按钮
					map7.put("status", "4");  // 红色(完成)
				}else if(orderUser.getType()==2 && isAgent==1) {  //下单用户为分销商且代理商点击确认取消按钮
					map7.put("status", "4");  // 红色(完成)
				}
			}else if((status==7 || status==9)) {	//厂家待批准阶段或厂家待发货阶段
				if(orderUser.getType()==3 && isTrader==1 && isAgent==1 && isVender==1) { //下单用户为电工,且分销商,代理商,厂家点击确认取消按钮
					map7.put("status", "4");  // 红色(完成)
				}else if(orderUser.getType()==2 && isAgent==1 && isVender==1) {  //下单用户为分销商且代理商,厂家点击确认取消按钮
					map7.put("status", "4");  // 红色(完成)
				}else if(orderUser.getType()==1 && isVender==1) { //下单用户为代理商且厂家点击确认取消按钮
					map7.put("status", "4");  // 红色(完成)
				}
			}
			
			//判断访问接口的用户类型和是否已点击确认取消按钮
			if(user.getType()==2 && isTrader==1) { //分销商且点击
				map7.put("status", "4");  // 红色(完成)
			}else if(user.getType()==1 && isAgent==1) { //代理商且点击
				map7.put("status", "4");  // 红色(完成)
			}
		}
		
		//判断下单用户类型
		if(orderUser.getType()==3) {  //电工提交的订单
//			map1.put("status", "2");  //灰色
			if(type==1) {
				processList.remove(map2); //电工的直接上级是代理商,移除分销商模块
				map6.put("title", "代理");  //代理收货
			}
			//若电工的直接上级是代理商且访问接口的用户是代理商
			if(StringUtils.isBlank(oRoleLevel.getTraderid()) && user.getType()==1) {
				isEdit = 1;    //显示修改地址按钮
				//若电工的直接上级是分销商且访问接口的用户是分销商
			}else if(StringUtils.isNoneBlank(oRoleLevel.getTraderid()) && user.getType()==2){
				isEdit = 1;		//显示修改地址按钮
			}
		}else if(orderUser.getType()==2) { //分销商提交的订单
			processList.remove(map1);  //移除掉电工模块
			map2.put("name", "提交");  //分销商提交
		}else if(orderUser.getType()==1) { //代理商提交的订单
			processList.remove(map1);  //移除掉电工模块
			processList.remove(map2);  //移除掉分销商模块
			map3.put("name", "提交");  //代理商提交
			map6.put("title", "代理");
		}
		
		//判断访问接口的用户类型
		if(user.getType()==3) { //电工
			//去除订单电工上级的物流地址
		/*	orderDetailMap.remove("addressee");
			orderDetailMap.remove("addresseePhone");
			orderDetailMap.remove("address");*/
			
			//去除分销商,代理商价格
			orderDetailMap.remove("agentPrice");
			orderDetailMap.remove("traderPrice");
			
		}else if(user.getType()==2) { //分销商
			//去除代理商价格
			orderDetailMap.remove("agentPrice");
		}else if(user.getType()==1) { //代理商
			//去除分销商价格
//			orderDetailMap.remove("traderPrice");
		}
		orderDetailMap.put("sendTime", processDetail.get("sendTime"));
		
		//根据orderId获取获取物流信息
		String shippingState="未发货";
		String shippingAddress="未有地址信息";
		Map<String,Object> map = shippingMapper.getShippingCodeByOrderId(orderId);
		if(map!=null&&!map.isEmpty()&&
				map.get("shippingCode")!=null&&StringUtils.isNotBlank(map.get("shippingCode").toString())) {
			Map<String,Object> resultShipping = LogisticsUtil.getLogisticsResult(
					map.get("shippingCode").toString(),eBusinessID,kuaidiniaoAppKey);
		
			Map<String,Object> results = (Map<String, Object>) resultShipping.get("result");
			if(results != null && !results.isEmpty()) {
				if(results.get("State")!=null && results.get("Traces")!=null) {
					shippingState=(String) results.get("State");
					if(shippingState.equals("2")) {
						shippingState="在途中";
					}
					if(shippingState.equals("3")) {
						shippingState="签收";
					}
					if(shippingState.equals("4")) {
						shippingState="问题件";
					}
					List<Map<String,Object>> traces = (List<Map<String, Object>>) results.get("Traces");
					if(traces!=null&&!traces.isEmpty()) {
						shippingAddress=(String) traces.get(0).get("AcceptStation");	
					}
				}
			}
		}
		
		//访问接口的用户是代理商
		if(user.getType()==1) {
			if(StringUtils.isNotBlank(oRoleLevel.getTraderid())) {
				showTraderPrice = 1;
			}
		}
		
		
		result.put("shippingState",shippingState);//物流状态2-在途中,3-签收,4-问题件
		result.put("shippingAddress",shippingAddress);//现在物流到哪了
		//设置返回信息
		result.put("orderDetail",orderDetailMap);  
		result.put("orderDetailItem", orderItemList);
		result.put("process", processList);   
		result.put("isFinish", isFinish);  //返回订单是否完成
		result.put("userType", user.getType());  //返回用户类型   3=电工  2=分销商  1=代理商
		result.put("isEdit", isEdit);   //是否显示修改地址按钮
		result.put("type", type);  //0包含分销商  1不包含
		result.put("showTraderPrice", showTraderPrice); //是否显示应收总价   0=否  1=是
		//设置格式
		Map<String, Object> check = this.settingSettlementMoney(result,orderItemList);
		if(check!=null) {
			return check;
		}
		
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK,result);
	}
	
	/**
	 * 整理商品信息 格式。
	 * @author chenluqiang
	 * @date 2019年1月19日 上午9:50:38 
	 * @param result
	 * @param orderItemList
	 * @return
	 */
	private Map<String, Object> settingSettlementMoney(Map<String, Object> resultMap,
			List<Map<String, Object>> goodsList) {
		
		Map<String,Map<String,Object>> allMap = new HashMap<String,Map<String,Object>>();
		//
		if(goodsList!=null&&!goodsList.isEmpty()) {
			for (Map<String, Object> map : goodsList) {
				//map
				if(map.get("categoryId")==null||StringUtils.isBlank(map.get("categoryId").toString())){
					return ResponseUtil.ajaxCheckError(ResultMessage.THIS_GOODS_NOT_CATEGORY,"categoryId is null~");
				}	
				//小类
				Map<String,Object> categoryMap =categoryMapper.getCategoryByCategoryId
							(Integer.parseInt(map.get("categoryId").toString()));

				if(categoryMap==null||categoryMap.isEmpty()||
						categoryMap.get("parentName")==null || StringUtils.isBlank(categoryMap.get("parentName").toString())) {
					return ResponseUtil.ajaxCheckError(ResultMessage.THIS_GOODS_NOT_LARGECATEGORY,"categoryMap is null~");
				}
				//拼接
				StringBuffer sb = new StringBuffer();
				sb.append(categoryMap.get("parentName").toString());
				sb.append("-");
				sb.append(categoryMap.get("categoryName").toString());
				
				categoryMap.put("nCategoryName", sb.toString());
				
				allMap.put(sb.toString(),categoryMap);
				
			}
			
			//整理返回格式
			for(Map<String,Object> categoryMap:allMap.values()) {
				List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
				for (Map<String, Object> map : goodsList) {
					if(categoryMap.get("categoryId").toString().equals(map.get("categoryId").toString())) {
						list.add(map);
					}
				}
				categoryMap.put("goods",list);
				//小计金额
				String minMoney = "0";
				//型号
				String number = "0";
				
				for(Map<String,Object> map :list) {
					String goodsPrice = MathUtils.multiply(map.get("goodsCount").toString(), map.get("goodsPrice").toString());
					minMoney = MathUtils.add(minMoney, goodsPrice);
					number = MathUtils.add("1", number);
				}
				categoryMap.put("minMoney",minMoney);
				categoryMap.put("number",number);
				
				categoryMap.remove("parentName");
				categoryMap.remove("categoryName");
			}
			
			
			resultMap.put("categorys", allMap.values());//
		}
		return null;
	}

	/**
	 * 只有已取消的订单才能 订单删除
	 * @author chenluqiang
	 * @date 2018年12月25日 上午10:11:06 
	 * @param orderId 订单id
	 * @return
	 */
	@Override
	public Map<String, Object> delOrder(User user, String orderId) {
		//校验orderId
		if(StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL,"orderId isnull~");
		}
		//删除订单流程
		/*Process process =new Process();
		process.setOrderid(orderId);
		process = processMapper.selectOne(process);
		if(process!=null&&process.getIscancel()==1
				&&process.getCanceluserid()!=null&&process.getStatus()==11) {
			//获取物流表id
			String shippnigId = orderMapper.getShippingIdByOrderId(orderId);
			//删除订单信息
			orderMapper.deleteByPrimaryKey(orderId);
			//删除订单item
			OrderItem orderItem = new OrderItem();
			orderItem.setOrderid(orderId);
			orderItemMapper.delete(orderItem);
			
			processMapper.deleteByPrimaryKey(process);
			//删除订单关联
			orderRoleLevelMapper.deleteByPrimaryKey(orderId);
			//删除物流信息
			shippingMapper.deleteByPrimaryKey(shippnigId);
			
			return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
		}else {
			return ResponseUtil.ajaxCheckError(ResultMessage.HAS_ISCANCEL);
		}*/
		
		//删除订单与该用户的关联
		/*ORoleLevel oRoleLevel = new ORoleLevel();
		oRoleLevel.setOrderid(orderId);
		oRoleLevel = orderRoleLevelMapper.selectByPrimaryKey(oRoleLevel);
		if(oRoleLevel==null) {
			return ResponseUtil.ajaxCheckError(ResultMessage.ORDERID_ISERROR,"orderId is error~");
		}
		if(StringUtils.isNotBlank(oRoleLevel.getAgentid())&&oRoleLevel.getAgentid().equals(user.getId())) {
			oRoleLevel.setAgentid(null);
		}else if(StringUtils.isNotBlank(oRoleLevel.getTraderid())&&oRoleLevel.getTraderid().equals(user.getId())) {
			oRoleLevel.setTraderid(null);
		}else if(StringUtils.isNotBlank(oRoleLevel.getElectid())&&oRoleLevel.getElectid().equals(user.getId())) {
			oRoleLevel.setElectid(null);
		}else {
			return ResponseUtil.ajaxCheckError(ResultMessage.ORDERID_ISERROR,"orderId is error~");
		}
		orderRoleLevelMapper.updateByPrimaryKey(oRoleLevel);*/
		Process process  = new Process();
		process.setOrderid(orderId);
		process = processMapper.selectOne(process);
		if(process==null) {
			return ResponseUtil.ajaxCheckError(ResultMessage.ORDERID_ISERROR,"orderId is error~");
		}
		//type 1=代理商 2=分销商(商家) 3=电工
		if(user.getType()==3) {
			process.setIselectshow(0);
		}else if(user.getType()==2) {
			process.setIstradershow(0);
		}else if(user.getType()==1) {
			process.setIsagentshow(0);
		}
		processMapper.updateByPrimaryKeySelective(process);
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}
	
	/**
	 * list图片处理
	 * @author chenluqiang
	 * @date 2018年12月18日 下午4:01:53 
	 * @param code key值
	 * @param list
	 */
	private void handleListPics(List<Map<String,Object>> list,String code) {
		//遍历处理
		if(list!=null&&!list.isEmpty()) {
			for(Map<String,Object> map : list) {
				if(map.get(code)!=null&&StringUtils.isNotBlank(map.get(code).toString())) {
					map.put(code, this.getPic(map.get(code).toString()));
				}
			}
		}
	}
	
	/**
	 * 拼接图片域名
	 * @author gujiahua
	 * 2018年11月28日 上午11:28:03
	 * @param pic
	 * @return
	 */
	private String getPic(String pic){
		if(!CheckUtil.checkUrl(pic)){
			pic =  fastdfsUrl+pic;
		}
		return pic;
	}

	/**
	 * (分销商或代理商)拒绝接单
	 * @author wujunyuan
	 * @date 2018年12月25日 上午10:05:43
	 * @param user
	 * @param orderId 订单id
	 * @return
	 */
	@Override
	public Map<String, Object> orderRefuse(User user, String orderId) {
		// 校验数据
		if (StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL, "orderId is null");
		}
		// 根据订单id获取订单流程信息
		Map<String, Object> processMap = processMapper.findProcessByOrderId(orderId);
		if (processMap != null) {
			String processId = (String) processMap.get("processId");
			// 是否取消订单 0=否 1=是
			Integer isCancel = (Integer) processMap.get("isCancel");
			Integer status = (Integer) processMap.get("status");
			if (isCancel != null && isCancel == 0) {
				if (status != null) {
					Process process = new Process();
					process.setId(processId);
					if (status == 3) {// 分销商待审核
						// 分销商审核不通过
						process.setStatus(4);
						process.setTraderpasstime(new Date());
						
					} else if (status == 5) {// 代理商待审核
						// 代理商审核不通过
						process.setStatus(6);
						process.setAgentpasstime(new Date());
					}
					process.setFinishtime(new Date());
					process.setUpdateTime(new Date());
					// 修改订单流程状态
					processMapper.updateByPrimaryKeySelective(process);
				}
			}
		}
		
//		user = userMapper.getUserByOrderId(orderId);
		ORoleLevel oRoleLevel = new ORoleLevel();
		oRoleLevel.setOrderid(orderId);
		oRoleLevel = orderRoleLevelMapper.selectOne(oRoleLevel);
		if(oRoleLevel!=null){
			if(StringUtils.isNotBlank(oRoleLevel.getTraderid())){
//				消息推送给分销商
				User Trader = userMapper.selectByPrimaryKey(oRoleLevel.getTraderid());
				JpushClientUtil.initJPushClient(ResultMessage.JGTSKEY, ResultMessage.JGTSECRET);
				if(Trader!=null&&StringUtils.isNoneBlank(Trader.getRegistrationId())) {
					JpushClientUtil.sendToRegistrationId(Trader.getRegistrationId(), "订单通知", "订单通知", "您的订单已被拒绝", "", "", "", new HashMap<>());
				}
			}
			if(StringUtils.isNotBlank(oRoleLevel.getElectid())){
//				消息推送给电工
				User Elect = userMapper.selectByPrimaryKey(oRoleLevel.getElectid());
				JpushClientUtil.initJPushClient(ResultMessage.JGTSKEY, ResultMessage.JGTSECRET);
				if(Elect!=null&&StringUtils.isNoneBlank(Elect.getRegistrationId())) {
					JpushClientUtil.sendToRegistrationId(Elect.getRegistrationId(), "订单通知", "订单通知", "您的订单已被拒绝", "", "", "", new HashMap<>());
				}
			}
		}
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}
	
	/**
	 * 提交审核
	 * @author wujunyuan
	 * @date 2018年12月25日  下午4:42:27
	 * @param user
	 * @param orderId 订单id
	 * @param addressee 上级收件人名称
	 * @param addresseephone 上级收件人电话
	 * @param address 上级收货地址
	 * @return
	 */
	@Override
	public Map<String, Object> orderSubmit(User user, String orderId, 
			String addressee, String addresseephone, String address) {
		// 校验数据
		if (StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL, "orderId is null");
		}
		// 上级收件人姓名
		if (StringUtils.isBlank(addressee)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_ERROR, "addressee error");
		}
		// 上级收件人电话
		if (StringUtils.isBlank(addresseephone)||!CheckUtil.checkMobile(addresseephone)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_ERROR, "addresseephone error");
		}
		// 上级收货地址
		if (StringUtils.isBlank(address)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_ERROR, "address error");
		}
		
		ORoleLevel oRoleLevel = new ORoleLevel();
		oRoleLevel.setOrderid(orderId);
		oRoleLevel = orderRoleLevelMapper.selectOne(oRoleLevel);
		
		// 根据订单id获取订单流程信息
		Map<String, Object> processMap = processMapper.findProcessByOrderId(orderId);
		if (processMap != null) {
			String processId = (String) processMap.get("processId");
			// 是否取消订单 0=否 1=是
			Integer isCancel = (Integer) processMap.get("isCancel");
			Integer status = (Integer) processMap.get("status");
			if (isCancel != null && isCancel == 0) {
				if (status != null) {
					Process process = new Process();
					process.setId(processId);
					if (status == 3) {// 分销商待审核
						process.setStatus(5);
						process.setTraderpasstime(new Date());
						if (oRoleLevel!=null && StringUtils.isNotBlank(oRoleLevel.getAgentid())) {
							User Agent = userMapper.selectByPrimaryKey(oRoleLevel.getAgentid());
//							 消息推送给代理商
							JpushClientUtil.initJPushClient(ResultMessage.JGTSKEY, ResultMessage.JGTSECRET);
							if(Agent!=null&&StringUtils.isNoneBlank(Agent.getRegistrationId())) {
								JpushClientUtil.sendToRegistrationId(Agent.getRegistrationId(), "订单通知", "订单通知", "您收到一个新订单,快去看看吧!", "", "", "", new HashMap<>());
							}
						}
						if (oRoleLevel!=null && StringUtils.isNotBlank(oRoleLevel.getElectid())) {
							User Elect = userMapper.selectByPrimaryKey(oRoleLevel.getElectid());
//							 消息推送给代理商
							JpushClientUtil.initJPushClient(ResultMessage.JGTSKEY, ResultMessage.JGTSECRET);
							if(Elect!=null&&StringUtils.isNoneBlank(Elect.getRegistrationId())) {
								JpushClientUtil.sendToRegistrationId(Elect.getRegistrationId(), "订单通知", "订单通知", "分销商已接单!", "", "", "", new HashMap<>());
							}
						}
					}
					else if (status == 5) {// 代理商待审核
						/*process.setStatus(7);
						process.setAgentpasstime(new Date());*/
						return ResponseUtil.ajaxCheckError(ResultMessage.PLESE_PAY);
					}
					process.setUpdateTime(new Date());
					// 修改订单流程状态
					processMapper.updateByPrimaryKeySelective(process);
					//添加新消息
					Message message = new Message();
					message.setId(UUID.randomUUID().toString().replace("-", ""));
					message.setCreateTime(new Date());
					message.setUpdateTime(new Date());
					message.setType(2);
					message.setIsRead(0); //未读状态
					message.setTitle("订单通知");
					message.setContent("您收到一个新订单,快去看看吧!");
					message.setUserid(user.getUserParentId());
					messageMapper.insertSelective(message);
				}
			}
		}
		// 根据订单id获取订单物流id
		 String shippingId = orderMapper.getShippingIdByOrderId(orderId);
		 if(StringUtils.isNotBlank(shippingId)) {
		 //根据物流表id更新收货地址
		 Shipping shipping = new Shipping();
		 shipping.setId(shippingId);
		 shipping.setAddressee(addressee);
		 shipping.setAddresseephone(addresseephone);
		 shipping.setAddress(address);
		 shippingMapper.updateByPrimaryKeySelective(shipping);
		 }
	
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}
	
	/**
	 * 申请取消订单
	 * @author wujunyuan
	 * @date 2018年12月25日  下午2:45:57
	 * @param user
	 * @param orderId 订单id
	 * @return
	 */
	@Override
	public Map<String, Object> orderCancel(User user, String orderId) {
		//校验参数
		if(StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL,"orderId is null");
		}
		//根据订单id获取订单流程表信息
		Map<String,Object> processMap = processMapper.findProcessByOrderId(orderId);
		if(processMap!=null) {
			String processId = (String) processMap.get("processId");
			// 是否取消订单 0=否 1=是
			Integer isCancel = (Integer) processMap.get("isCancel");
//			Integer status = (Integer) processMap.get("status");
			if(isCancel!=null&&isCancel==0) {
				Process process = new Process();
				process.setId(processId);
				//设置取消订单
				process.setIscancel(1);
				//设置申请取消订单的用户id
				process.setCanceluserid(user.getId());
//				//判断该用户的上级
//				if(user.getType()==3) {
//					int type = 0;
//					ORoleLevel oRoleLevel = orderRoleLevelMapper.selectByPrimaryKey(orderId);
//					if(StringUtils.isNoneBlank(oRoleLevel.getElectid()) && StringUtils.isBlank(oRoleLevel.getTraderid()) 
//							&& StringUtils.isNoneBlank(oRoleLevel.getAgentid())) { 
//						type = 1;  //若分销商为空,电工和代理商id不为空,说明电工的直接上级是代理商
//					}
//					if(type==0) {//上级是分销商
//						process.setStatus(3);
//					}else if(type==1) {//上级是代理商
//						process.setStatus(5);
//					}
//				}else if(user.getType()==2){
//					process.setStatus(5);
//				}else if(user.getType()==1) {
//					//订单已付款申请取消
//					if(status==7||status==9) {
//						process.setStatus(7);
//					}else {
//					//订单未付款申请取消
//						process.setStatus(6);
//					}
//				}
				
				process.setUpdateTime(new Date());
				//更新数据库字段isCancel和cancelUserId
				processMapper.updateByPrimaryKeySelective(process);
				
				//设置取消时间
				Order order = new Order();
				order.setId(orderId);
				order.setCanceltime(new Date());
				orderMapper.updateByPrimaryKeySelective(order);
			}
		}
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}

	/**
	 * (分销商/代理商)确认取消订单
	 * @author wujunyuan
	 * @date 2018年12月25日 下午3:19:25
	 * @param user
	 * @param orderId 订单id
	 * @return
	 */
	@Override
	public Map<String, Object> orderConfirmCancel(User user, String orderId) {
		// 校验参数
		if (StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL, "orderId is null");
		}
		// 根据订单id获取订单流程表信息
		Map<String, Object> processMap = processMapper.findProcessByOrderId(orderId);
		if (processMap != null) {
			String processId = (String) processMap.get("processId");
			// 是否取消订单 0=否 1=是
			Integer isCancel = (Integer) processMap.get("isCancel");
			Integer isTrader = (Integer) processMap.get("isTrader");
			Integer isAgent = (Integer) processMap.get("isAgent");
//			Integer status = (Integer) processMap.get("status");
			
			if (isCancel != null && isCancel == 1) {
				Process process = new Process();
				process.setId(processId);
				switch(user.getType()) {
					case 2://分销商
						if(isTrader!=null&&isTrader==0) {
							process.setIstrader(1);
//							if(status==3) {
//								process.setStatus(11);
//							}else {
//								process.setStatus(5);
//							}
						}
						break;
					case 1://代理商
						if(isAgent!=null&&isAgent==0) {
							process.setIsagent(1);
//							if(status==5){
//								process.setStatus(11);
//							}else {
//								process.setStatus(7);
//							}
						}
						break;
				}
				process.setUpdateTime(new Date());
				//更新数据库字段
				processMapper.updateByPrimaryKeySelective(process);
			}
		}
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}

	/**
	 * 确认收货
	 * @author wujunyuan
	 * @date 2018年12月25日 下午3:52:16
	 * @param user
	 * @param orderId 订单id
	 * @return
	 */
	@Override
	public Map<String, Object> orderConfirmReceived(User user, String orderId) {
		// 校验参数
		if (StringUtils.isBlank(orderId)) {
			return ResponseUtil.ajaxCheckError(ResultMessage.PARAMETER_NULL, "orderId is null");
		}
		// 根据订单id获取订单流程表信息
		Map<String, Object> processMap = processMapper.findProcessByOrderId(orderId);
		if (processMap != null) {
			String processId = (String) processMap.get("processId");
			Process process = new Process();
			process.setId(processId);
			//11=完成 
			process.setStatus(11);
			process.setIsRefund(1);
			process.setReceivetime(new Date());
			process.setFinishtime(new Date());
			process.setUpdateTime(new Date());
			//更新数据库字段
			processMapper.updateByPrimaryKeySelective(process);
			
			ORoleLevel oRoleLevel = new ORoleLevel();
			oRoleLevel.setOrderid(orderId);
			oRoleLevel = orderRoleLevelMapper.selectOne(oRoleLevel);
			if(oRoleLevel!=null){
				if(StringUtils.isNotBlank(oRoleLevel.getElectid())){
//					消息推送给电工
					User Elect = userMapper.selectByPrimaryKey(oRoleLevel.getElectid());
					JpushClientUtil.initJPushClient(ResultMessage.JGTSKEY, ResultMessage.JGTSECRET);
					if(StringUtils.isNoneBlank(Elect.getRegistrationId())) {
						JpushClientUtil.sendToRegistrationId(Elect.getRegistrationId(), "订单通知", "订单通知", "订单已收到货！", "", "", "", new HashMap<>());
					}
				}
			}
		}
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}
	
	/**
	 * 支付宝回调
	 */
	@Override
	public boolean orderNotify(Map<String, String> params) {
		String tradeStatus = params.get("trade_status");// 获取交易状态
		String totalAmount= params.get("total_amount");//订单金额:本次交易支付的订单金额，单位为人民币（元）
		String appId= params.get("app_id");//支付宝分配给开发者的应用Id
		String tradeNo=params.get("trade_no");//支付宝的交易号
		String paymentNum = params.get("out_trade_no");//获取商户之前传给支付宝的订单号（商户系统的唯一订单号）
		System.out.println("=======================================================");
		System.out.println(tradeStatus);
		System.out.println(totalAmount);
		System.out.println(appId);
		System.out.println(tradeNo);
		System.out.println(paymentNum);
		
		Order order = new Order();
		order.setPaymentnum(paymentNum);
		order = orderMapper.selectOne(order);
		if(order==null) {
			return false;
		}
		Process process = new Process();
		process.setOrderid(order.getId());
		process = processMapper.selectOne(process);
		if(process==null) {
			return false;
		}
		if(process.getStatus()!=5) {
			return false;
		}
		
		System.out.println(order.getAgentprice());
		System.out.println(APP_ID);
		System.out.println(totalAmount);
		System.out.println("=======================================================");
		String paymentPrice = MathUtils.sub(order.getAgentprice(), order.getWalletprice());
		System.out.println("paymentPrice----------------"+paymentPrice);
		if(order!=null && paymentPrice.equals(totalAmount) && appId.equals(APP_ID)) {
			if(tradeStatus.equals("TRADE_SUCCESS")) {
				//修改订单
				order.setTradeno(tradeNo);
				order.setPaytype(2);
				order.setPayTime(new Date());
				order.setPaystatus(1);
				order.setUpdateTime(new Date());
				orderMapper.updateByPrimaryKeySelective(order);
				//修改订单流程状态
				process.setStatus(7);  //厂家待批准状态
				process.setUpdateTime(new Date());
				processMapper.updateByPrimaryKeySelective(process);
				
				if(StringUtils.isNoneBlank(order.getWalletprice())) {
					
					Wallet wallet = walletMapper.getWalletByUserId(order.getUserid());
					wallet.setMoney(MathUtils.sub(wallet.getMoney(), order.getWalletprice()));
					walletMapper.updateByPrimaryKeySelective(wallet);
					
				}
				return true;
			} else {
				return false;
			}
		}else {
			logger.info("==================支付宝官方建议校验的值（out_trade_no、total_amount、sellerId、app_id）,不一致！返回fail");
			return false;
		}
	}

	/**
	 * 修改订单收货地址
	 *
	 * @author lihongwu
	 * 2019年1月18日 下午5:31:33
	 * @param orderId
	 * @param addressId
	 * @return
	 */
	@Override
	public Map<String, Object> editReciverAddress(String orderId, String addressId) {
		Address address = addressMapper.selectByPrimaryKey(addressId);
		Shipping shipping = shippingMapper.getShippingByOrderId(orderId);
		shipping.setAddressee(address.getName());
		shipping.setAddresseephone(address.getPhone());
		shipping.setAddress(address.getProvince()+address.getCity()+address.getArea()+address.getAddress());
		shippingMapper.updateByPrimaryKeySelective(shipping);
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK);
	}

}
